//
//  SimpleScheduleCell.m
//  GolfFriend
//
//  Created by vescky on 13-11-30.
//  Copyright (c) 2013年 vescky.org. All rights reserved.
//

#import "SimpleScheduleCell.h"
#import "CommonUtility.h"

@interface SimpleScheduleCell ()

@end

@implementation SimpleScheduleCell

- (void)setCellDataInfo:(ScheduleContentVo*)cContent {
    
    float fontSize = 12;
    
    if ([cContent.status intValue] == -1) {
        [imgViewFlag setImage:[UIImage imageNamed:@"hp_schedule_gray.png"]];
    }
    else if ([cContent.status intValue] == 0) {
        //正在进行的事项
        [imgViewFlag setImage:[UIImage imageNamed:@"hp_schedule_red.png"]];
        fontSize = 15;
    }
    else {
        [imgViewFlag setImage:[UIImage imageNamed:@"hp_schedule_black.png"]];
    }
    [labelDate setFont:[UIFont systemFontOfSize:fontSize]];
    [labelDate setText:cContent.dateString];
    
    [labelTime setFont:[UIFont systemFontOfSize:fontSize]];
    [labelTime setText:[NSString stringWithFormat:@"~%@",cContent.timeString]];
    
    //根据文字长度，决定label的高度
    [labelContent setFont:[UIFont systemFontOfSize:fontSize]];
    CGRect contentRect = labelContent.frame;
    CGRect cellRect = self.frame;
    contentRect.size.height = GetStringSize(cContent.content, fontSize, nil, CGSizeMake(160, 2000)).height;
    if (contentRect.size.height > cellRect.size.height) {
        cellRect.size.height = contentRect.size.height;
        [self setFrame:cellRect];
        [labelContent setFrame:contentRect];
        CGRect imgRect = imgViewFlag.frame;
        imgRect.origin.y = (cellRect.size.height - imgRect.size.height)/2.0;
        [imgViewFlag setFrame:imgRect];
    }
    [labelContent setText:cContent.content];
}

- (float)getContentHeight:(ScheduleContentVo*)cContent {
    float fontSize = 12;
    if ([cContent.status intValue] == 0) {
        fontSize = 15;
    }
    float contentHeight = GetStringSize(cContent.content, fontSize, nil, CGSizeMake(160, 2000)).height;
    if (self.frame.size.height < contentHeight) {
        return contentHeight;
    }
    return self.frame.size.height;
}

@end
